<?php

class config {

	public function Read($source,$item)
	{
		include('db/dbConfig.php');
		include(${$key}[$source]);
		return ${$item};
	}

	public function Write($source,$item,$value)
	{
		include('db/dbConfig.php');
		include(${$key}[$source]);
		$old = file_get_contents(${$key}[$source]);
		$oldstr = "\${$item} = '{${$item}}';";
		$newstr = "\${$item} = '{$value}';";
		$new = str_replace($oldstr,$newstr,$old);
		$file = fopen(${$key}[$source],w);
		fwrite($file,$new);
		fclose($file);
	}

	public function Add($source,$item,$value)
	{
		include('db/dbConfig.php');
		$old = file_get_contents(${$key}[$source]);
		$oldstr = "#WRITE";
		$newstr = "#WRITE\n\${$item} = '{$value}';";
		$new = str_replace($oldstr,$newstr,$old);
		$file = fopen(${$key}[$source],w);
		fwrite($file,$new);
		fclose($file);
	}

	public function Remove($source,$item)
	{
		include('db/dbConfig.php');
		include(${$key}[$source]);
		$old = file_get_contents(${$key}[$source]);
		$oldstr = "\${$item} = '{${$item}}';";
		$newstr = null;
		$new = str_replace($oldstr,$newstr,$old);
		$file = fopen(${$key}[$source],w);
		fwrite($file,$new);
		fclose($file);
	}
	
}

$config = new config();

?>
